package com.project.everywheretakeaway;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.SharedPreferences;
import android.view.Menu;

public class MyMapActivity extends Activity {

	public static final String MAP_PREFS = "MAP_PREF";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.map_layout);
		
		//SharedPreferences mySharedPreferences = getSharedPreferences(MAP_PREFS,Activity.MODE_PRIVATE);
		Context context = getApplicationContext();
		SharedPreferences mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
		
		int id = Integer.parseInt(mySharedPreferences.getString("id", "0"));
		String name = mySharedPreferences.getString("name", "Default Name");
		double latitude = Double.parseDouble(mySharedPreferences.getString("lat", "0"));
		double longitude = Double.parseDouble(mySharedPreferences.getString("lng", "0"));
				
		FragmentManager fm = getFragmentManager();
		//FragmentTransaction ft = fm.beginTransaction();
		
		MapFragment mapFragment = (MapFragment)fm.findFragmentById(R.id.map);
		GoogleMap map = mapFragment.getMap();		
		
		
		CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(latitude, longitude)).zoom(19).build();
 
		map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
		
		map.addMarker(new MarkerOptions().position(new LatLng(latitude,longitude)).title(name));
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.my_map, menu);
		return true;
	}

}
